package com.buyingtickets.controller;


import com.buyingtickets.entity.QueryWelcome;
import com.buyingtickets.entity.Statistics;
import com.buyingtickets.service.WelcomeBiz;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author czl
 * @version 1.0
 * @description: TODO
 * @date 2021/6/24 9:30
 */
@Controller
public class WelcomeController {
    @Resource
    private WelcomeBiz welcomeBiz;
    @RequestMapping("welcome")
    @ResponseBody
    public List<Statistics> queryForList(){
        QueryWelcome qw=new QueryWelcome();
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
        String today=dateFormat.format(date);
        qw.setToday(today);
        qw.setChecileixing("K");
        int kcheci=welcomeBiz.queryChuXingRenShu(qw);
        qw.setChecileixing("G");
        int gcheci=welcomeBiz.queryChuXingRenShu(qw);
        qw.setChecileixing("Z");
        int zcheci=welcomeBiz.queryChuXingRenShu(qw);
        List<Statistics> array = new ArrayList<Statistics>();
        array.add(new Statistics("K车型出行人数", kcheci));
        array.add(new Statistics("G车型出行人数", gcheci));
        array.add(new Statistics("Z车型出行人数", zcheci));

        return array;
    }
    @RequestMapping("welcome1")
    @ResponseBody
    public List<Statistics> queryForList1(){
        QueryWelcome qw=new QueryWelcome();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance(); //创建Calendar 的实例
        String today = fmt.format(calendar.getTime());
        qw.setToday(today);
        int dingdanshu=welcomeBiz.queryDingDanShu(qw);
        List<Statistics> array = new ArrayList<Statistics>();
        array.add(new Statistics(today, dingdanshu));
        for (int i=1;i<7;i++){
            calendar.add(Calendar.DAY_OF_MONTH,-1); //当前时间减去一天，即一天前的时间
            String today2 = fmt.format(calendar.getTime());
            qw.setToday(today2);
            int dingdanshu2=welcomeBiz.queryDingDanShu(qw);
            array.add(new Statistics(today2, dingdanshu2));
        }
        return array;
    }

    @RequestMapping("towelcome")
    public String towelcome(QueryWelcome qw,Model model){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
        String today=dateFormat.format(date);
        qw.setToday(today);
        int yonghu=welcomeBiz.queryYongHu();
        int chuxingreshu=welcomeBiz.queryChuXingRenShu(qw);
        int dingdanshu=welcomeBiz.queryDingDanShu(qw);
        int chengke=welcomeBiz.queryChengKe();
        qw.setChengke(chengke);
        qw.setTodaytuxingrenshu(chuxingreshu);
        qw.setYonghu(yonghu);
        qw.setDingdanshu(dingdanshu);
        model.addAttribute("qw",qw);
        return "welcome";
    }
}
